package cn.datawin.date;

import cn.hutool.core.date.*;
import cn.hutool.core.lang.ObjectId;

import java.util.Date;

public class Demo {

    public static void main(String[] args) {
        //1、获取当前时间的固定pattern
        String yyyyMMdd = DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN);
        System.out.println("yyyyMMdd = " + yyyyMMdd);
        //2、获取时间的偏离量
        DateTime parse = DateUtil.parse(yyyyMMdd, DatePattern.PURE_DATE_PATTERN).offset(DateField.DAY_OF_MONTH,1);
        System.out.println("parse = " + parse);
        DateTime parse1 = DateUtil.offsetDay(new Date(),-1);
        System.out.println("parse1 = " + parse1);
        //获取当前时间的零点然后往前推一天
        DateTime date = new DateTime();
        DateTime parse2 = DateUtil.offsetDay(DateUtil.beginOfDay(date),-1);//DateUtil.beginOfDay(date).offset( DateField.DAY_OF_YEAR, -1)
        System.out.println("parse2 = " + parse2);
        //获取当前时间的零点然后往前推一天，再往前推15min
        DateTime parse3 = DateUtil.beginOfDay(date).offset( DateField.DAY_OF_YEAR, -1).offset(DateField.MINUTE,-15);
        System.out.println("parse3 = " + parse3);
        //获取两个时间之间的间隔
        Date date1 = DateUtil.parse("20240111 10:59:00","yyyyMMdd HH:mm:ss");
        Date date2 = DateUtil.parse("20240111 10:56:00","yyyyMMdd HH:mm:ss");
        long between = DateUtil.between(date1, date2, DateUnit.MINUTE);
        System.out.println("between = " + between);
    }
}
